#!/usr/bin/env bash
# Revert commits by list in CSV (list is generated by find-broken-commits-updates_tracker.sh)
# "${git_repo};${commit_hash};https://abf.io/import/${git_repo}/commit/${commit_hash}" 

if [ -z "$REPO_DIR" ]; then
	echo 'Define $REPO_DIR!'
	exit 1
fi

if [ -z "$list" ]; then
	echo 'Define $list!'
	exit 1
fi

set -efu

while read -r line
do
	git_repo="$(echo "$line" | awk -F ';' '{print $1}' | awk -F '/' '{print $NF}')"
	commit_hash="$(echo "$line" | awk -F ';' '{print $2}')"
	pushd "$REPO_DIR/$git_repo"
	git revert "$commit_hash"
	git push
	popd
done < <(cat "$list")
